<template>
  <div>
    <top-bar></top-bar>
    <left-bar :datas='data'></left-bar>
    <div class="main">
      <div class="main-mains">
        <div class="main-content">
          <div class="main-mains-top">
            用户审核
          </div>
          <div class="publicTable toLongTable">
            <table class="head_table">
              <tr>
                <td width="3%">序号</td>
                <td width="5%">用户账号</td>
                <td width='5%'>用户实名</td>
                <td width='12%'>用户身份证号</td>
                <td width='7%'>用户申请角色</td>
                <td width='10%'>申请认证日期</td>
                <td width='7%'>认证资料</td>
                <td width='12%'>所属地区</td>
                <td width="5%">账号状态</td>
                <td width='7%'>操作</td>
              </tr>
            </table>
            <el-scrollbar>
              <table class="content_table">
                <tr v-for="(item,index) in listData" :key="index" :class="{active:index%2==1}">
                  <td width="3%">{{index+1}}</td>
                  <td width="5%">{{item.content.username}}</td>
                  <td width="5%">{{item.content.real_name}}</td>
                  <td width="12%">{{item.content.idcard_no}}</td>
                  <td width="7%">{{item.content.role_zh}}</td>
                  <td width="10%">{{item.create_time | times}}</td>
                  <td width="7%">
                    <span class="active" @click="getDetails(item.id)">查看</span>
                  </td>
                  <td width="12%">{{region(item.content.province,item.content.city,item.content.area)}}</td>
                  <td width="5%">{{ item.auth_status| statusType}}</td>
                  <td width="7%" v-if="item.auth_status==0">
                    <span class="active" @click="adopt(item.id)">通过</span>&nbsp;&nbsp;
                    <span class="active" @click="refuse(item.id)">拒绝</span>
                  </td>
                  <td width="7%" v-else>

                  </td>
                </tr>
              </table>
            </el-scrollbar>
          </div>
          <div class="nodataTip" v-if="showNodataTip">
            <i class="iconfont icon-zanwuneirong"></i>
            <h5>暂无内容</h5>
          </div>
          <div class="orderBotom">
            <div class="orderBotomRight">
              <el-pagination @current-change="handleCurrentChange" :page-size="15" layout="total, prev, pager, next" :total='totalnum'>
              </el-pagination>
            </div>
          </div>
        </div>
      </div>
      <div class="system-menban" v-if="search"></div>
      <div class="systemPopup" v-if="search">
        <div class="topTitle">
          <span>筛选用户</span>
          <i class="el-icon-close system-icon" @click="hideSystemPopup"></i>
        </div>
        <div class="systemPopup-con">
          <div class="systemPopup-cons clear">
            <div class="fl">时间</div>
            <div class="fl sel">
              <el-date-picker value-format="timestamp" v-model="time" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
              </el-date-picker>
            </div>
          </div>
          <div class="systemPopup-cons clear">
            <div class="fl">选择角色</div>
            <div class="fl sel">
              <el-select v-model="role" placeholder="请选择认证角色">
                <el-option v-for="item in roleType" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
          </div>
          <div class="systemPopup-btn clear">
            <div class="fl" @click="searchs()">确认</div>
            <div class="fl" @click="hideSystemPopup">取消</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>


<script>
import leftBar from "@/components/leftBar";
import topBar from "@/components/topBar";
import user from "@/api/user";
export default {
  components: {
    leftBar,
    topBar
  },
  data() {
    return {
      data: "userExamine",
      pages: 1,
      listData: [],
      totalnum: 0,
      showNodataTip: false,
      search: false,
      time: "",
      role: "",
      roleType: []
    };
  },
  methods: {
    screen() {
      this.search = true;
    },
    hideSystemPopup() {
      this.search = false;
    },
    refuse(id) {
      this.$prompt("请输入拒绝理由", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消"
      })
        .then(({ value }) => {
          if (value == null || value == "") {
            this.$message({
              showClose: true,
              message: "请填写拒绝理由!",
              type: "error"
            });
            return false;
          }
          const options = {
            manage_id: id,
            status: "reject",
            comment: value
          };
          user.manageUserAuthStatus(options).then(res => {
            if (res.code == 1) {
              this.$message({
                showClose: true,
                message: "拒绝成功！",
                type: "success"
              });
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消输入"
          });
        });
    },
    adopt(id) {
      //通过
      let _this = this;
      _this
        .$confirm("此操作将通过该账户, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
        .then(() => {
          const options = {
            manage_id: id,
            status: "pass"
          };
          user.manageUserAuthStatus(options).then(res => {
            if (res.code == 1) {
              this.$message({
                showClose: true,
                message: "通过成功！",
                type: "success"
              });
              this.getList();
            }
          });
        })
        .catch(() => {
          _this.$message({
            type: "info",
            message: "已取消冻结"
          });
        });
    },
    getDetails(id) {
      this.$router.push("/userInfos/" + id);
    },
    region(area1, area2, area3) {
      const areas1 = area1 ? area1 : "";
      const areas2 = area2 ? area2 : "";
      const areas3 = area3 ? area3 : "";
      return areas1 + areas2 + areas3;
    },
    handleCurrentChange(val) {
      this.pages = val;
      this.getList();
    },
    getList() {
      this.showNodataTip = false;
      const options = {
        page: this.pages,
        status: ""
      };
      user.getUserAuthList(options).then(res => {
        if (res.code == 1) {
          this.listData = res.data.list;
          this.totalnum = res.data.total;
          if (!res.data.total) {
            this.showNodataTip = true;
          }
        }
      });
    },
    getRoleLists() {
      const options = {};
      user.getRoleList(options).then(res => {
        if (res.code == 1) {
          for (let i = 0; i < res.data.list.length; i++) {
            this.roleType.push({
              value: res.data.list[i].id,
              label: res.data.list[i].name
            });
          }
        }
      });
    }
  },
  mounted() {
    this.getList();
    this.getRoleLists();
  },
  filters: {
    times(value) {
      var time = new Date(value * 1000);
      var month =
        time.getMonth() + 1 > 9
          ? time.getMonth() + 1
          : "0" + (time.getMonth() + 1);
      var data = time.getDate() > 9 ? time.getDate() : "0" + time.getDate();
      var hour = time.getHours() > 9 ? time.getHours() : "0" + time.getHours();
      var minutes =
        time.getMinutes() > 9 ? time.getMinutes() : "0" + time.getMinutes();
      var second =
        time.getSeconds() > 9 ? time.getSeconds() : "0" + time.getSeconds();
      var times =
        time.getFullYear() +
        "-" +
        month +
        "-" +
        data +
        " " +
        hour +
        ":" +
        minutes +
        ":" +
        second;
      return times;
    },
    statusType(val) {
      let type;
      if (val == 0) {
        type = "待审核";
      } else if (val == 1) {
        type = "正常";
      } else if (val == 2) {
        type = "已拒绝";
      }
      return type;
    }
  }
};
</script>

<style>
</style>
